package com.ruoyi.project.anquan.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.anquan.domain.SecurityYh;
import com.ruoyi.project.anquan.service.ISecurityYhService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 隐患Controller
 * 
 * @author ruoyi
 * @date 2020-05-13
 */
@RestController
@RequestMapping("/anquan/yh")
public class SecurityYhController extends BaseController
{
    @Autowired
    private ISecurityYhService securityYhService;

    /**
     * 查询隐患列表
     */
    @PreAuthorize("@ss.hasPermi('anquan:yh:list')")
    @GetMapping("/list")
    public TableDataInfo list(SecurityYh securityYh)
    {
        startPage();
        List<SecurityYh> list = securityYhService.selectSecurityYhList(securityYh);
        return getDataTable(list);
    }

    /**
     * 导出隐患列表
     */
    @PreAuthorize("@ss.hasPermi('anquan:yh:export')")
    @Log(title = "隐患", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SecurityYh securityYh)
    {
        List<SecurityYh> list = securityYhService.selectSecurityYhList(securityYh);
        ExcelUtil<SecurityYh> util = new ExcelUtil<SecurityYh>(SecurityYh.class);
        return util.exportExcel(list, "yh");
    }

    /**
     * 获取隐患详细信息
     */
    @PreAuthorize("@ss.hasPermi('anquan:yh:query')")
    @GetMapping(value = "/{yhId}")
    public AjaxResult getInfo(@PathVariable("yhId") Long yhId)
    {
        return AjaxResult.success(securityYhService.selectSecurityYhById(yhId));
    }

    /**
     * 新增隐患
     */
    @PreAuthorize("@ss.hasPermi('anquan:yh:add')")
    @Log(title = "隐患", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SecurityYh securityYh)
    {
        return toAjax(securityYhService.insertSecurityYh(securityYh));
    }

    /**
     * 修改隐患
     */
    @PreAuthorize("@ss.hasPermi('anquan:yh:edit')")
    @Log(title = "隐患", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SecurityYh securityYh)
    {
        return toAjax(securityYhService.updateSecurityYh(securityYh));
    }

    /**
     * 删除隐患
     */
    @PreAuthorize("@ss.hasPermi('anquan:yh:remove')")
    @Log(title = "隐患", businessType = BusinessType.DELETE)
	@DeleteMapping("/{yhIds}")
    public AjaxResult remove(@PathVariable Long[] yhIds)
    {
        return toAjax(securityYhService.deleteSecurityYhByIds(yhIds));
    }
}
